package com.jari.lg.service.analysis.keyarea;

import com.jari.lg.domain.DevBase;
import com.jari.lg.domain.ScenicSpotCarDay;
import com.jari.lg.domain.ScenicSpotNolocalCarDay;
import com.jari.lg.mapper.ScenicSpotCarDayMapper;
import com.jari.lg.mapper.ScenicSpotNolocalCarDayMapper;
import com.jari.lg.utils.BaseData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class ScenicSpotService {

    @Resource
    private ScenicSpotCarDayMapper scenicSpotCarDayMapper;
    @Resource
    private ScenicSpotNolocalCarDayMapper scenicSpotNolocalCarDayMapper;

    protected void CreateScenicSpot() throws ParseException {

        String[] province = new String[]{"北京市", "天津市", "河北省", "山西省", "内蒙古自治区", "辽宁省",
                "吉林省", "黑龙江省", "江苏省", "浙江省", "安徽省", "福建省", "江西省", "山东省", "河南省",
                "湖北省", "湖南省", "广东省", "广西壮族自治区", "海南省", "重庆市", "四川省", "贵州省",
                "云南省", "西藏自治区", "陕西省", "甘肃省", "青海省", "宁夏回族自治区", "新疆维吾尔自治区", "香港特别行政区", "澳门特别行政区", "台湾省"};

        List<ScenicSpotCarDay> ansLocal = new ArrayList<>();
        List<ScenicSpotNolocalCarDay> ansNoLocal = new ArrayList<>();

        List<DevBase> checkPoint = BaseData.checkpointList;

        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(format1.parse("2021-04-01 00:00:00"));

        for (int i = 0; i < 12; i++) {
            int dayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            for (int j = 0; j < dayOfMonth; j++) {
                for (DevBase d : checkPoint) {
                    ScenicSpotCarDay scenicSpotCarDay = new ScenicSpotCarDay();
                    ScenicSpotNolocalCarDay scenicSpotNolocalCarDay = new ScenicSpotNolocalCarDay();

                    scenicSpotCarDay.setCheckpointcode(d.getDevicecode());
                    scenicSpotCarDay.setCheckpointname(d.getDevicename());
                    scenicSpotCarDay.setPassingcarnum(new Random().nextInt(200));//每天过车0-200
                    scenicSpotCarDay.setLocalcarnum((int) (0.9 * scenicSpotCarDay.getPassingcarnum()));
                    scenicSpotCarDay.setNolocalcarnum(scenicSpotCarDay.getPassingcarnum() - scenicSpotCarDay.getLocalcarnum());
                    scenicSpotCarDay.setDate(calendar.getTime());

                    scenicSpotNolocalCarDay.setCheckpointcode(d.getDevicecode());
                    scenicSpotNolocalCarDay.setCheckpointname(d.getDevicename());
                    scenicSpotNolocalCarDay.setNolocalcarprovince(province[new Random().nextInt(33)]);//随机省份
                    scenicSpotNolocalCarDay.setNolocalcarnum(scenicSpotCarDay.getPassingcarnum() - scenicSpotCarDay.getLocalcarnum());
                    scenicSpotNolocalCarDay.setDatetime(calendar.getTime());

                    ansLocal.add(scenicSpotCarDay);
                    ansNoLocal.add(scenicSpotNolocalCarDay);
                }
                calendar.add(Calendar.DATE, 1);//加1天
            }
            scenicSpotCarDayMapper.insertBatch(ansLocal);
            scenicSpotNolocalCarDayMapper.insertBatch(ansNoLocal);
            ansLocal.clear();
            ansNoLocal.clear();
        }

    }

}
